package com.cx.string;

import java.io.StringReader;

/**
 * @author zhangshuai
 * @version V1.0
 * @Project Java2_26
 * @Package com.cx.string
 * @Description:
 * @Date 2025/5/22 8:07
 */

public class StringTest1 {

    public static void main(String[] args) {
        //字符串拆分
        String str = "123aasfsdfsdf,456dsfsdfss789,saa,adafda,asdfasdfasdf";
        String[] strs1 = {"123", "aasfsdfsdf", "456dsfsdfss", "789", "saa", "adafda", "asdfasdfasdf"};

        String[] split = str.split(",");
        for (String s : split) {
            System.out.println(s);
        }

        //字符串拼接  + concat
        String str1 = "123";
        String str2 = "456";
        String str3 = "789";
        //1.使用 + 拼接  之后都是新的字符串  不安全，效率低
        String str12 =  str1 + str2 + str3;
        System.out.println(str12);
        //2.使用 concat 拼接
        String str13 = str1.concat(str3).concat(str2).concat(str3);
        System.out.println(str13);

        String join = str1.join("++++", str1, str3, str2, str3);
        System.out.println(join);
        //[1,4)
        String substring = str13.substring(1, 4);
        System.out.println(substring);
        String ss = "  111    adfasd   adada  adad ";
        //去除字符串前后空格
        String trim = ss.trim();
        System.out.println(trim);
        String[] s = trim.split(" ");
        for (String s1 : s) {
            System.out.println(s1);
        }
        String replace = trim.replace(" ", "");
        System.out.println(replace);

        String str4 = "123456789";
        int a  = 20;
        double b = 20.044564;

        String format = String.format("%d", a);
        System.out.println(format);
        String format1 = String.format("%.3f", b);
        System.out.println(format1);
        String format2 = String.format("%s", str4);
        System.out.println(format2);

        MyString myString = new MyString();

    }
}
@SuppressWarnings("deprecation")
@Deprecated
class MyString{
    static String str = "123";
}